package com.example.service.impl;

import com.example.common.Result;
import com.example.mapper.SupplyCategoryMapper;
import com.example.service.SupplyCategoryService;
import com.example.vo.SupplyCategoryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class SupplyCategoryServiceImpl implements SupplyCategoryService {
    
    @Autowired
    private SupplyCategoryMapper supplyCategoryMapper;
    
    @Override
    public Result<List<SupplyCategoryVO>> getAllEnabledSupplyCategories() {
        try {
            List<SupplyCategoryVO> supplyCategories = supplyCategoryMapper.selectAllEnabled();
            return Result.success(supplyCategories);
        } catch (Exception e) {
            log.error("查询所有启用的供货分类失败", e);
            return Result.error("查询供货分类列表失败");
        }
    }
    
    @Override
    public Result<SupplyCategoryVO> getSupplyCategoryById(Long id) {
        try {
            SupplyCategoryVO supplyCategoryVO = supplyCategoryMapper.selectVOById(id);
            if (supplyCategoryVO == null) {
                return Result.error("供货分类不存在");
            }
            return Result.success(supplyCategoryVO);
        } catch (Exception e) {
            log.error("查询供货分类失败，分类ID: {}", id, e);
            return Result.error("查询供货分类失败");
        }
    }
} 